/*
 * Cache
 *
 * Creado el 06/05/2009, 05:22:44 PM
 */
package com.unicon.autoservicio.util;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * 
 * @author Ricardo Rodríguez
 */
public final class Cache {

   private static String CACHE_NAME = "app";

   public static <T> void put(Object key, T value) {
      net.sf.ehcache.Cache cache = 
              CacheManager.getInstance().getCache(CACHE_NAME);
      Element element = new Element(key, value);
      cache.put(element);
   }

   @SuppressWarnings("unchecked")
   public static <T> T get(Object key) {
      net.sf.ehcache.Cache cache =
              CacheManager.getInstance().getCache(CACHE_NAME);
      Element element = cache.get(key);
      try {
         return (T)element.getObjectValue();
      } catch (Exception e) {
         return null;
      }
   }

   public static void remove(Object key) {
      net.sf.ehcache.Cache cache =
              CacheManager.getInstance().getCache(CACHE_NAME);
      cache.remove(key);
   }
}
